﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SysMenuManage.aspx.cs" Inherits="GU.WebERPApp.Sys.SysMenuManage" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/Scripts/mini.boot.js" type="text/javascript"></script>
    <script src="/Scripts/Plugin/msgTip.js" type="text/javascript"></script>
</head>
<body>
    <form runat="server" id="form1">
    <div id="dvOperation" style="margin-bottom:5px;">
        <a id="btnAdd" class="mini-button" iconcls="icon-add" plain="true" onclick="addNode()">新增菜单</a>
        <a id="btnEdit" class="mini-button" iconcls="icon-edit" plain="true" onclick="editNode()">编辑菜单</a>
        <a id="btnDelete" class="mini-button" iconcls="icon-remove" plain="true" onclick="onRemoveNode()">删除菜单</a>
    </div>
    <div id="treegrid1" class="mini-treegrid" style="width:800px;height:280px;"     
        url="/methods/?method=itm.sys.menu.get" showTreeIcon="true" 
        treeColumn="MenuName" idField="MenuId" parentField="ParentId" resultAsTree="false" expandOnLoad="true">
        <div property="columns">
            <div type="indexcolumn" width="15"></div>
            <div name="MenuName" field="MenuName" width="80" headeralign="center">菜单名称</div>
            <div field="Sort" width="20" headeralign="center" align="center">排序</div>
            <div field="Link"  headeralign="center" width="180">链接</div>
            <div field="Remark" width="80"  headeralign="center">备注</div>
            <div field="Rec_CreateTime" width="60" dateFormat="yyyy-MM-dd" headeralign="center" align="center">创建日期</div>                  
        </div>
    </div>
    <div id="win1" class="mini-window" title="Window" style="width:330px;height:250px;" 
        showFooter="true" showModal="true" allowDrag="true">
        <div property="footer" style="text-align:right;padding:5px;padding-right:15px;">
            <a id="A5" class="mini-button" iconcls="icon-ok" plain="true" onclick="saveMenu()">  保存  </a>
            <a id="A6" class="mini-button" iconcls="icon-no" plain="true" onclick="hideWindow('win1')">  取消  </a>
        </div>
        <table id="tabMenuInfo" border="0" cellpadding="3" cellspacing="2">
            <tr>
                <td>父菜单：</td>
                <td colspan="3" style="vertical-align:middle">
                    <div style="float:left;">
                        <span id="parentMenu" style="color:Blue;">根菜单</span>
                        <input id="MenuId" name="MenuId" value="0" class="mini-hidden" />
                        <input id="ParentId" name="ParentId" value="0" class="mini-hidden" />
                    </div>
                    <div style="float:right;">
                        <a id="A3" class="mini-button" iconcls="icon-folderopen" plain="true" onclick="openSelectMenu()">选择父菜单</a>
                    </div>
                </td>
            </tr>
            <tr>
                <td>菜单名：</td>
                <td colspan="3">
                    <input id="MenuName" name="MenuName" style="width:200px;" class="mini-textbox" required="true" />
                </td>
            </tr>
            <tr>
                <td >链接：</td>
                <td colspan="3">
                    <input id="Link" name="Link" style="width:200px;" class="mini-textbox"/>
                </td>
            </tr>
            <tr>
                <td >排序：</td>
                <td >
                    <input id="Sort" name="Sort"  style="width:80px;" class="mini-spinner" minValue="1"/>
                </td>
                <td>是否显示：</td>
                <td>
                    <input id="Display" name="Display" class="mini-checkbox" required="true" />
                </td>
            </tr>
            <tr>
                <td >备注：</td>
                <td colspan="3">
                    <input id="Remark" name="Remark" style="width:200px;" class="mini-textbox" />
                </td>
            </tr>
        </table>
    </div>
    <div id="winTreeMenu" class="mini-window" title="Window" style="width:250px;height:300px;" 
        showFooter="true" showModal="true" allowDrag="true">
        <div property="footer" style="text-align:right;padding:5px;padding-right:15px;">
            <a id="A1" class="mini-button" iconcls="icon-ok" plain="true" onclick="onSelectMenu()">  确定  </a>
            <a id="A2" class="mini-button" iconcls="icon-no" plain="true" onclick="hideWindow('winTreeMenu')">  取消  </a>
        </div>
        <div class="mini-fit">
            <ul id="tree1" class="mini-tree" style="width:100%;height:100%;" 
                showTreeIcon="true" textField="MenuName"  idField="MenuId" parentField="ParentId" resultAsTree="false"  
                expandOnLoad="true" onnodedblclick="onSelectMenu" expandOnDblClick="false" >
            </ul>
        </div>
    </div>
    </form>
    <script type="text/javascript">
        var _type = "";
        function addNode() {
            openWin("win1", "添加系统菜单");
            _type = "add";
            var form = new mini.Form("#tabMenuInfo");
            form.setData({});
        }

        function editNode() {
            var node = mini.get("treegrid1").getSelectedNode();
            if (node == null) {
                mini.alert("请选择需要修改的菜单！");
                return;
            }
            openWin("win1", "修改系统菜单");
            _type = "edit";
            var form = new mini.Form("#tabMenuInfo");
            form.setData(node);

            if (node.ParentId > 0) {
                ygopAjaxClient.async("itm.sys.menu.getsingle", "post", { "mid": node.ParentId }, function (e) {
                    var data = mini.decode(e.RspData.data);
                    $("#parentMenu").text(data.MenuName);
                });
            }
            else {
                $("#parentMenu").text("根菜单");
            }
        }

        function openSelectMenu() {
            openWin("winTreeMenu", "选择父菜单");
            mini.get("tree1").load("/methods/?method=itm.sys.menu.get");
            /*ygopAjaxClient.async("itm.sys.menu.get", "get", null, function (e) {
            mini.get("tree1").setData(mini.decode(e));
            //mini.get("tree1").load();
            });*/
        }

        function onRemoveNode() {
            var node = mini.get("treegrid1").getSelectedNode();
            if (node == null) {
                mini.alert("请选择你要删除的菜单！");
                return;
            }
            mini.confirm("确定删除 “" + node.MenuName + "” 菜单？", "确定？", function (action) {
                if (action == "ok") {
                    ygopAjaxClient.async("itm.sys.menu.delete", "post", { "mid": node.MenuId }, function (e) {
                        if (e.RspCode == 1) {
                            $.alert(e.RspMsg);
                            self.location.reload();
                        }
                        else {
                            mini.alert(e.RspMsg);
                        }
                    });
                }
            });
        }

        function openWin(id, title) {
            var win = mini.get(id);
            win.setTitle(title);
            win.show();
        }

        function hideWindow(id) {
            var win = mini.get(id);
            win.hide();
        }

        function onSelectMenu() {
            var node = mini.get("tree1").getSelectedNode();
            if (node == null) {
                mini.alert("请选择父菜单！");
                return;
            }
            if (node.MenuId != "0" && node.MenuId == mini.get("MenuId").getValue()) {
                mini.alert("不能选择自己作为父菜单!");
                return;
            }
            mini.get("ParentId").setValue(node.MenuId);
            $("#parentMenu").text(node.MenuName);
            hideWindow('winTreeMenu');
        }

        function saveMenu() {
            var form = new mini.Form("#tabMenuInfo");
            form.validate();
            if (form.isValid() == false) return;

            var data = form.getData();
            data.Display = data.Display == "true" ? 1 : 0;
            var s = encodeURI(mini.encode(data));
            if (_type == "add") {
                ygopAjaxClient.async("itm.sys.menu.add", "post", { "data": s }, function (e) {
                    if (e.RspCode == 1) {
                        $.alert(e.RspMsg);
                        hideWindow('win1');
                        self.location.reload();
                    }
                    else
                        mini.alert(e.RspMsg)
                });
            }
            else if (_type == "edit") {
                ygopAjaxClient.async("itm.sys.menu.edit", "post", { "data": s }, function (e) {
                    if (e.RspCode == 1) {
                        $.alert(e.RspMsg);
                        hideWindow('win1');
                        self.location.reload();
                    }
                    else
                        mini.alert(e.RspMsg)
                });
            }
        }
    </script>
</body>
</html>
